/*
 Navicat Premium Dump SQL

 Source Server         : localhost
 Source Server Type    : MySQL
 Source Server Version : 80030 (8.0.30)
 Source Host           : localhost:3306
 Source Schema         : security-demo

 Target Server Type    : MySQL
 Target Server Version : 80030 (8.0.30)
 File Encoding         : 65001

 Date: 15/09/2025 19:49:11
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for permission
-- ----------------------------
DROP TABLE IF EXISTS `permission`;
CREATE TABLE `permission` (
  `permission_id` int NOT NULL AUTO_INCREMENT COMMENT '权限ID',
  `permission_name` varchar(100) NOT NULL COMMENT '权限名称',
  `description` varchar(255) DEFAULT NULL COMMENT '权限描述',
  PRIMARY KEY (`permission_id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4;

-- ----------------------------
-- Records of permission
-- ----------------------------
BEGIN;
INSERT INTO `permission` (`permission_id`, `permission_name`, `description`) VALUES (1, 'USER_READ', '查看用户信息');
INSERT INTO `permission` (`permission_id`, `permission_name`, `description`) VALUES (2, 'USER_ADD', '新增用户信息');
INSERT INTO `permission` (`permission_id`, `permission_name`, `description`) VALUES (3, 'ROLE_MANAGE', '管理角色');
INSERT INTO `permission` (`permission_id`, `permission_name`, `description`) VALUES (4, 'PERMISSION_MANAGE', '管理权限');
INSERT INTO `permission` (`permission_id`, `permission_name`, `description`) VALUES (5, 'DATA_VIEW', '查看数据');
INSERT INTO `permission` (`permission_id`, `permission_name`, `description`) VALUES (6, 'DATA_EXPORT', '导出数据');
COMMIT;

-- ----------------------------
-- Table structure for role
-- ----------------------------
DROP TABLE IF EXISTS `role`;
CREATE TABLE `role` (
  `role_id` int NOT NULL AUTO_INCREMENT COMMENT '角色ID',
  `role_name` varchar(100) NOT NULL COMMENT '角色名称',
  `description` varchar(255) DEFAULT NULL COMMENT '角色描述',
  PRIMARY KEY (`role_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;

-- ----------------------------
-- Records of role
-- ----------------------------
BEGIN;
INSERT INTO `role` (`role_id`, `role_name`, `description`) VALUES (1, 'ADMIN', '管理员，拥有所有权限');
INSERT INTO `role` (`role_id`, `role_name`, `description`) VALUES (2, 'USER', '普通用户，拥有基本权限');
INSERT INTO `role` (`role_id`, `role_name`, `description`) VALUES (3, 'GUEST', '访客，只读权限');
COMMIT;

-- ----------------------------
-- Table structure for role_permission
-- ----------------------------
DROP TABLE IF EXISTS `role_permission`;
CREATE TABLE `role_permission` (
  `role_permission_id` int NOT NULL AUTO_INCREMENT COMMENT '角色权限关联ID',
  `role_id` int NOT NULL COMMENT '角色ID',
  `permission_id` int NOT NULL COMMENT '权限ID',
  PRIMARY KEY (`role_permission_id`),
  KEY `fk_role_rp` (`role_id`),
  KEY `fk_permission_rp` (`permission_id`),
  CONSTRAINT `fk_permission_rp` FOREIGN KEY (`permission_id`) REFERENCES `permission` (`permission_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_role_rp` FOREIGN KEY (`role_id`) REFERENCES `role` (`role_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4;

-- ----------------------------
-- Records of role_permission
-- ----------------------------
BEGIN;
INSERT INTO `role_permission` (`role_permission_id`, `role_id`, `permission_id`) VALUES (1, 1, 1);
INSERT INTO `role_permission` (`role_permission_id`, `role_id`, `permission_id`) VALUES (2, 1, 2);
INSERT INTO `role_permission` (`role_permission_id`, `role_id`, `permission_id`) VALUES (3, 1, 3);
INSERT INTO `role_permission` (`role_permission_id`, `role_id`, `permission_id`) VALUES (4, 1, 4);
INSERT INTO `role_permission` (`role_permission_id`, `role_id`, `permission_id`) VALUES (5, 1, 5);
INSERT INTO `role_permission` (`role_permission_id`, `role_id`, `permission_id`) VALUES (6, 1, 6);
INSERT INTO `role_permission` (`role_permission_id`, `role_id`, `permission_id`) VALUES (7, 2, 5);
INSERT INTO `role_permission` (`role_permission_id`, `role_id`, `permission_id`) VALUES (8, 2, 6);
INSERT INTO `role_permission` (`role_permission_id`, `role_id`, `permission_id`) VALUES (9, 3, 5);
COMMIT;

-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
  `user_id` int NOT NULL AUTO_INCREMENT,
  `username` varchar(50) DEFAULT NULL,
  `password` varchar(500) DEFAULT NULL,
  `enabled` tinyint(1) NOT NULL,
  PRIMARY KEY (`user_id`) USING BTREE,
  UNIQUE KEY `user_username_uindex` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4;

-- ----------------------------
-- Records of user
-- ----------------------------
BEGIN;
INSERT INTO `user` (`user_id`, `username`, `password`, `enabled`) VALUES (1, 'admin', '{bcrypt}$2a$10$GRLdNijSQMUvl/au9ofL.eDwmoohzzS7.rmNSJZ.0FxO/BTk76klW', 1);
INSERT INTO `user` (`user_id`, `username`, `password`, `enabled`) VALUES (2, 'Helen', '{bcrypt}$2a$10$GRLdNijSQMUvl/au9ofL.eDwmoohzzS7.rmNSJZ.0FxO/BTk76klW', 1);
INSERT INTO `user` (`user_id`, `username`, `password`, `enabled`) VALUES (3, 'Tom', '{bcrypt}$2a$10$GRLdNijSQMUvl/au9ofL.eDwmoohzzS7.rmNSJZ.0FxO/BTk76klW', 1);
INSERT INTO `user` (`user_id`, `username`, `password`, `enabled`) VALUES (5, 'chen', '{bcrypt}$2a$10$HAtUwigy.mHi1upDq.qPde0l67KHJUc.uePI7pAYNMvIba8FD79Uu', 1);
INSERT INTO `user` (`user_id`, `username`, `password`, `enabled`) VALUES (6, 'chen1', '{bcrypt}$2a$10$RB9owAey8yrUh5cFQ0bNauEk/1rogrIi6Tr9SabLP2OP5hRvtrJ3W', 1);
INSERT INTO `user` (`user_id`, `username`, `password`, `enabled`) VALUES (7, 'chen11', '{bcrypt}$2a$10$2/o7JRNM9.1axGv/js9Ei.6IrL3zLE.FOWlfz4zsooNyMv2a3CX.a', 1);
INSERT INTO `user` (`user_id`, `username`, `password`, `enabled`) VALUES (8, 'chen111', '{bcrypt}$2a$10$EPS0sdZfcMxugOxmhJFcy.QiUBesc5f5JaR6esEb98JSViXXswLGy', 1);
COMMIT;

-- ----------------------------
-- Table structure for user_role
-- ----------------------------
DROP TABLE IF EXISTS `user_role`;
CREATE TABLE `user_role` (
  `user_role_id` int NOT NULL AUTO_INCREMENT COMMENT '用户角色关联ID',
  `user_id` int NOT NULL COMMENT '用户ID',
  `role_id` int NOT NULL COMMENT '角色ID',
  PRIMARY KEY (`user_role_id`),
  KEY `fk_user` (`user_id`),
  KEY `fk_role` (`role_id`),
  CONSTRAINT `fk_role` FOREIGN KEY (`role_id`) REFERENCES `role` (`role_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_user` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;

-- ----------------------------
-- Records of user_role
-- ----------------------------
BEGIN;
INSERT INTO `user_role` (`user_role_id`, `user_id`, `role_id`) VALUES (1, 1, 1);
INSERT INTO `user_role` (`user_role_id`, `user_id`, `role_id`) VALUES (2, 2, 2);
INSERT INTO `user_role` (`user_role_id`, `user_id`, `role_id`) VALUES (3, 3, 3);
COMMIT;

SET FOREIGN_KEY_CHECKS = 1;
